Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report more detailed reason why Index impl is not satisfied #110432

Merged
merged 3 commits into from
Apr 19, 2023

Conversation

compiler-errors
Copy link
Member

Fixes #110373

@rustbot
Copy link
Collaborator

rustbot commented Apr 16, 2023

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 16, 2023
compiler/rustc_hir_typeck/src/expr.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/expr.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/expr.rs Outdated Show resolved Hide resolved
if let Some((_, index_ty, element_ty)) =
self.find_and_report_unsatisfied_index_impl(expr.hir_id, base, base_t)
{
self.demand_coerce(idx, idx_t, index_ty, None, AllowTwoPhase::No);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we registering a coercion? To avoid ambiguities later?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly just copying the confirmation logic from the happy path. Leaving it unconstrained probably isn't great, but I haven't thought much about creating additional spurious errors from this.

let errors = ocx.select_where_possible();
// There should be at least one error reported. If not, we
// will still delay a span bug in `report_fulfillment_errors`.
Ok::<_, NoSolution>((
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are emitting an error, why are we committing inference constraints?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because otherwise we wouldn't be able to return a useful return type here for later typechecking to use. I guess we could return ty::Error here or something, but I prefer recoveries to be as accurate as possible for downstream typechecking.

compiler/rustc_hir_typeck/src/expr.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/expr.rs Outdated Show resolved Hide resolved
@rustbot
Copy link
Collaborator

rustbot commented Apr 18, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@compiler-errors
Copy link
Member Author

@cjgillot, I messed with the test a bit to justify what the index ty coercion and that commit_if_ok is for by demonstrating some downstream errors that result from confirming this Index impl. Hope that helps a bit.

@@ -0,0 +1,27 @@
use std::hash::Hash;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would've marked this as // run-rustfix but I cannot due to overlapping suggestion spans. I'll fix that in a different PR.

@cjgillot
Copy link
Contributor

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Apr 18, 2023

📌 Commit 8d75a8f has been approved by cjgillot

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 19, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#110432 (Report more detailed reason why `Index` impl is not satisfied)
 - rust-lang#110451 (Minor changes to `IndexVec::ensure_contains_elem` & related methods)
 - rust-lang#110476 (Delay a good path bug on drop for `TypeErrCtxt` (instead of a regular delayed bug))
 - rust-lang#110498 (Switch to `EarlyBinder` for `collect_return_position_impl_trait_in_trait_tys`)
 - rust-lang#110507 (boostrap: print output during building tools)
 - rust-lang#110510 (Fix ICE for transmutability in candidate assembly)
 - rust-lang#110513 (make `non_upper_case_globals` lint not report trait impls)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3320b2a into rust-lang:master Apr 19, 2023
@rustbot rustbot added this to the 1.71.0 milestone Apr 19, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 29, 2023
… r=cjgillot

Tweak borrow suggestion span

Avoids a `span_to_snippet` call when we don't need to surround the expression in parentheses. The fact that the suggestion was using the whole span of the expression rather than just appending a `&` was prevented me from using `// run-rustfix` in another PR (rust-lang#110432 (comment)).

Also some drive-by renames of functions that have been annoying me for a bit.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 29, 2023
… r=cjgillot

Tweak borrow suggestion span

Avoids a `span_to_snippet` call when we don't need to surround the expression in parentheses. The fact that the suggestion was using the whole span of the expression rather than just appending a `&` was prevented me from using `// run-rustfix` in another PR (rust-lang#110432 (comment)).

Also some drive-by renames of functions that have been annoying me for a bit.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 1, 2023
… r=cjgillot

Tweak borrow suggestion span

Avoids a `span_to_snippet` call when we don't need to surround the expression in parentheses. The fact that the suggestion was using the whole span of the expression rather than just appending a `&` was prevented me from using `// run-rustfix` in another PR (rust-lang#110432 (comment)).

Also some drive-by renames of functions that have been annoying me for a bit.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request May 9, 2023
… r=cjgillot

Tweak borrow suggestion span

Avoids a `span_to_snippet` call when we don't need to surround the expression in parentheses. The fact that the suggestion was using the whole span of the expression rather than just appending a `&` was prevented me from using `// run-rustfix` in another PR (rust-lang#110432 (comment)).

Also some drive-by renames of functions that have been annoying me for a bit.
@compiler-errors compiler-errors deleted the unsatisfied-index-impl branch August 11, 2023 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message E0608 when the type supports Index but Idx is missing trait bounds
4 participants